<template>
  <forms ref="forms" :config="config" @submit:forms="onsubmit" :btns="btns">
  </forms>
</template>

<script>
export default {
  props: ['__iframe'],
  data(){
    let id = this.$get('id'), btns = undefined;
    let admin = this.admin_config('this_admin', {});
    let forms_config = {
      name: {label: '用户名', name: 'name', tips: '用户名，登录用，不可修改', value:admin.name},
      nickname: {label: '昵称', name: 'nickname', type: 'text_one', tips: '', value:admin.nickname},
      truename: {label: '真实姓名', name: 'truename', type: 'text_one', tips: '', value:admin.truename},
      head_img: {label: '头像', name: 'head_img', type: 'file_img', tips: '管理员头像，建议尺寸100*100', value:admin.head_img},
      role_id: {label: '角色', name: 'admin_role_name', tips: '', value:admin.admin_role_name},
      contact: {label: '手机号', name: 'phone', type: 'text_one', tips: '手机号', value:admin.phone},
      information: {label: '简介', name: 'info', type: 'text_more', tips: '简介、彰显个性和特点的一段话', value:admin.info},
      create_time: {label: '创建时间', name: 'create_time', tips: '', value:admin.create_time}
    }
    if (this.$get('is_info')){
      s94Mjs.each(forms_config, function (row){ row.is_info = true; });
      btns = [];
    }
    return {
      id: id,
      btns: btns,
      config: forms_config,
    }
  },
  methods: {
    onsubmit(formData){
      let url = '/admin/index/edit';
      ajax({url:url, method:'POST', data:formData}, (res)=>{
        let admin = s94Mjs.merge(this.admin, res.data);
        this.admin_config({'admin': admin});
        if (this.__iframe){
          iframe.hide('edit_self');
        }else {
          this.$router.push('home');
        }
      }, (res)=>{
        if (res.errors) this.$refs['forms'].errors = res.errors;
      })
    }
  },
  mounted() {
    let app = this;
    if (!this.__iframe) window['app'] = this;

  }
}
</script>
